home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Online
/
Joe's-PPP-Scripts
/
PPP Connection
/
•PPP connection (text)
< prev
next >
Wrap
Text File
|
1996-08-20
|
8KB
|
288 lines
property openFile : {""}
property closeFile : {""}
property forwardFile : {""}
property ftp_directory : {""}
global transferFile, parsedFile, useDirectory, serverResponse
global LF, CR, CRLF
global intermediateResult, fileName, sss
global newsockets, socketsList
on run
if openFile = {""} then
set dialogText to {"Select a HTML file to be sent at OPEN connection:"}
getFilelocation(dialogText)
set openFile to result
end if
if closeFile = {""} then
set dialogText to {"Select a HTML file to be sent at CLOSE connection:"}
getFilelocation(dialogText)
set closeFile to result
end if
if ftp_directory = {""} then
set dialog_response to (display dialog "Enter the directory to use for the HTML files:" default answer "www_docs" buttons "OK" default button "OK")
set ftp_directory to text returned of dialog_response
end if
if forwardFile = {""} then
set dialogText to {"Select an E-mail \".forward\" file:"}
getFilelocation(dialogText)
set forwardFile to result
end if
openPPP (getPPPServer)
repeat while not (PPPopened)
end repeat
checkMail()
set transferFile to {""}
open for access file openFile
set transferFile to (read openFile)
close access openFile
dealwithFile()
set fileName to "currentIP.html"
set useDirectory to true
ftpPlanfile()
set transferFile to {""}
open for access file forwardFile
set transferFile to (read forwardFile)
close access forwardFile
dealwithFile()
set fileName to ".forward"
set useDirectory to false
ftpPlanfile()
set LF to ASCII character (10)
set socketsList to {}
repeat with x from 1 to 2
set newSocket to {tcp wait for connect port 666}
set socketsList to socketsList & newSocket
end repeat
end run
on checkMail()
set mmm to (tcp connect to host (GetICPreference SMTP host) port 110)
try
readresponse(mmm)
tcp write data "USER " & (GetICPreference mail account) & return stream mmm using ISO88591
readresponse(mmm)
tcp write data "PASS " & (GetICPreference mail password) & return stream mmm using ISO88591
readresponse(mmm)
tcp write data "STAT" & return stream mmm using ISO88591
readresponse(mmm)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set messageCount to text item 2 of serverResponse as integer
set AppleScript's text item delimiters to oldDelimiters
if messageCount ≠ 0 then
if messageCount = 1 then
speak "There is one message"
else
speak "There are " & messageCount & " new messages"
end if
else
speak "There are no messages"
end if
tcp close stream mmm
on error
display dialog "Error with mail check" buttons {"OK"} default button "OK"
end try
end checkMail
on getFilelocation(dialogText)
try
set fileLocation to (choose file with prompt ¬
dialogText of type {"TEXT"}) as string
on error errMsg
abort()
end try
end getFilelocation
on dealwithFile()
try
searchReplace of me into transferFile at "%ip%" given replaceString:(tcp my address)
set intermediateResult to result as text
on error errMsg
abort()
end try
try
searchReplace of me into intermediateResult at "%clock%" given replaceString:(current date)
set parsedFile to result as text
on error errMsg
abort()
end try
end dealwithFile
on searchReplace into mainString at searchString given replaceString:replaceString
repeat while mainString contains searchString
set foundOffset to offset of searchString in mainString
set stringStart to text 1 thru (foundOffset - 1) of mainString
set stringEnd to text (foundOffset + (count of searchString)) thru -1 of mainString
set mainString to stringStart & replaceString & stringEnd
end repeat
return mainString
end searchReplace
on ftpPlanfile()
set LF to (ASCII character of 10)
set CR to (ASCII character of 13)
set CRLF to CR & LF
try
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set localAddr to (tcp my address)
set localAddrList to text items of localAddr
set AppleScript's text item delimiters to {","}
set localAddrCommaString to localAddrList as string
set AppleScript's text item delimiters to oldDelimiters
set sss to (tcp connect to host (GetICPreference ftp host) port 21)
try
readresponse(sss)
tcp write stream sss data "USER " & (GetICPreference mail account) & return using ISO88591
readresponse(sss)
tcp write stream sss data "PASS " & (GetICPreference mail password) & return using ISO88591
readresponse(sss)
if useDirectory = true then
tcp write stream sss data "CWD " & ftp_directory & return using ISO88591
readresponse(sss)
end if
tcp write stream sss data "TYPE A" & return using ISO88591
readresponse(sss)
set data_stream to (tcp wait for connect)
set data_stream_status to (tcp status stream data_stream)
set portHiByte to round (local port of data_stream_status) / 256 rounding down
set portLoByte to (local port of data_stream_status) mod 256
tcp write stream sss data "PORT " & localAddrCommaString & "," & portHiByte & "," & portLoByte & return using ISO88591
readresponse(sss)
tcp write stream sss data "STOR " & fileName & return & LF
readresponse(sss)
repeat until (connection status of (tcp status stream data_stream) = Connected)
end repeat
tcp write stream data_stream data parsedFile using ISO88591
try
on error msg number num from obj partial result pr
tcp close stream data_stream
error msg number num from data_stream
end try
tcp close stream data_stream
readresponse(sss)
tcp write stream sss data "QUIT" & return using ISO88591
readresponse(sss)
tcp close stream sss
on error msg number num from obj partial result pr
try
tcp write stream sss data "QUIT" & return using ISO88591
readresponse(sss)
on error
end try
tcp close stream sss
error msg number num from obj partial result pr
end try
on error errMsg
abort()
end try
end ftpPlanfile
on readresponse(sstream)
set LF to ASCII character (10)
repeat until (tcp ahead characters LF stream sstream)
end repeat
set serverResponse to (tcp read until characters LF stream sstream using ISO88591)
end readresponse
on idle
if (PPPopened) then
set newsockets to {}
repeat with x from 1 to (length of socketsList)
set s to item x of socketsList
try
set itsStatus to (tcp status stream s)
if connection status of itsStatus = Connected then
set newsockets to newsockets & {tcp wait for connect port 666}
handleConnection(s)
else
set newsockets to newsockets & {s}
end if
on error
end try
end repeat
set socketsList to newsockets
set newsockets to {}
return 10
else
quit
end if
end idle
on handleConnection(s)
try
speak "There is new E-mail"
tcp close stream s
on error
try
tcp close stream s
on error
end try
end try
end handleConnection
on abort()
display dialog "Error. Script aborted" buttons {"OK"} default button "OK"
set openFile to {""}
set closeFile to {""}
set forwardFile to {""}
set ftp_directory to {""}
try
tcp close stream sss
on error
end try
quit
end abort
on quit
try
repeat with x from 1 to (length of socketsList)
set s to item x of socketsList
try
tcp close stream s
on error
end try
end repeat
if (PPPopened) then
set transferFile to {""}
open for access file closeFile
set transferFile to (read closeFile)
close access closeFile
dealwithFile()
set fileName to "currentIP.html"
set useDirectory to true
ftpPlanfile()
closePPP with hard close
end if
on error
end try
continue quit
end quit